package com.wyz.rabbitmqconsumer.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class TTLRabbitmqConfig {

    @Bean
    public DirectExchange getTTLDirectExchange(){
        return new DirectExchange("ttl_direct_exchange", true, false);
    }

    @Bean
    public Queue getTTLDirectSmsQueue(){
        Map<String,Object> args = new HashMap<>();
        args.put("x-message-ttl", 5000);
        args.put("x-max-length", 5);  // 最大队列数量
        args.put("x-dead-letter-exchange", "dead_direct_exchange");
        args.put("x-dead-letter-routing-key", "dead");
        return new Queue("ttl.direct.queue", true, false, false, args);
    }

    @Bean
    public Queue getTTLMessageSmsQueue(){
        return new Queue("ttl.message.direct.queue", true);
    }

    @Bean
    public Binding getTTLDirectSmsBinding(){
        return BindingBuilder.bind(getTTLDirectSmsQueue()).to(getTTLDirectExchange()).with("ttl");
    }

    @Bean
    public Binding getTTLMessageSmsBinding(){
        return BindingBuilder.bind(getTTLMessageSmsQueue()).to(getTTLDirectExchange()).with("message");
    }

}
